<link rel="stylesheet" href="js/plugins/bootstrap/datapicker/bootstrap-datetimepicker.min.css">
<script src="js/plugins/bootstrap/datapicker/bootstrap-datetimepicker.min.js"></script>
<script src="js/plugins/bootstrap/datapicker/bootstrap-datetimepicker.zh-CN.js"></script>

<link rel="stylesheet" href="css/plugins/summernote/summernote.css">
<script src="js/plugins/summernote/summernote.min.js"></script>
<style>
    .form-group{
        margin-left: 5px;
    }
    .input-group{
        width: 100%;
    }
    .nt{
        width: 200px;
        height: 40px;
        background-color: 	#F0F0F0;
    }
    .bt{
        height: 40px;
    }
    error{
        /*     border-color: red; */
        border: 1px dotted #cc5965;
    }
</style>
<div class="ibox-content">
    <form class="form-inline" style="padding-left: 10px;">
        <!--<div class="form-group">
            <select id=“organization” class="form-control" style="width: 100px;height: 34px;">
                <option value="-1">发布机构</option>
                <option value="0">银行</option>
                <option value="1">金融机构</option>
                <option value="2">担保机构</option>
            </select>
        </div>
        <div class="form-group">
            <select id="status" class="form-control" style="width: 100px;height: 34px;">
                <option value="-1">审核状态</option>
                <option value="0">未审核</option>
                <option value="1">已审核</option>
                <option value="2">已退回</option>
            </select>
        </div>-->
        <!--<div class="form-group">-->
            <!--<input type="text" readonly class="form_datetime" validata="{'type':'date'}"  value="" id="createTime1" style="width:200px; height: 34px;">-->
            <!--至-->
            <!--<input type="text" readonly class="form_datetime" validata="{'type':'date'}"  value="" id="createTime2" style="width:200px; height: 34px;">-->
        <!--</div>-->
        <!--<div class="form-group">-->
            <!--<input type="text" class="form-control" id="title" placeholder="标题" style="width: 150px;">-->
        <!--</div>-->
        <!--<button type="button" onclick="search()" class="btn btn-primary">搜索</button>-->
    </form>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="table-responsive">
            <table id="list" class="table table-striped table-bordered table-hover dataTables-example dataTable">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>用户名</th>
                    <th>电话</th>
                    <th>性别</th>
                    <th>地址</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    $("#createTime1").datetimepicker({
        format:"yyyy-mm-dd",
        autoclose:"true",
        todayHighlight:"true",
        language:'zh-CN'
    })
    $("#createTime2").datetimepicker({
        format:"yyyy-mm-dd",
        autoclose:"true",
        todayHighlight:"true",
        language:'zh-CN'
    })

    $('.summernote').summernote({
        height: 115,   //set editable area's height
        codemirror: { // codemirror options
            theme: 'monokai'
        },
        shortcuts: false
    });

    function search(_b){
        window.history_list_url = bathpath + '/wx/user/getUserList';
        if (_b != -1) {
            window.history_list.ajax.url(window.history_list_url).load()
            return false
        }
        window.history_list = $('#list').DataTable({
            searching: false,
            serverSide: true,
            ajax: {
                type: 'post',
                url: history_list_url,
                data: function (d) {

                },
                dataSrcOption: "data"
            },
            processing: true, //是否显示处理状态
            /* order: [
                [5, 'desc']
            ], */
            //序号
            fnDrawCallback: function () {
                this.api().column(0).nodes().each(function (cell, i) {
                    cell.innerHTML = i + 1;
                });
            },
            columns: [{
                "orderable": false,
                "data": null
            }, {
                "orderable": false,
                "data": "nick_name"
            }, {
                "orderable": false,
                "data": "phone",

            }, {
                "orderable": false,
                "data": "sex"
            }, {
                "orderable": false,
                "data": null,
                render: function (dom, a, b) {
                    return dom.province+""+dom.city+""+dom.county
                }
            },{
                "orderable": false,
                "data": null,
                render: function (dom, a, b) {
                    var str = "";
                    if(b.status==0){
                        str += "<a class='btn btn-sm btn-primary m-t-n-xs' href='javascript:void(0)' onclick='audit("+b.id+",1)'>通过</a>&nbsp;&nbsp;";
                        str += "<a class='btn btn-sm btn-primary m-t-n-xs' href='javascript:void(0)' onclick='audit("+b.id+",2)'>拒绝</a>&nbsp;&nbsp;";
                    }
                    if(b.status==1){
                        str += "<a class='btn btn-sm btn-primary m-t-n-xs' href='javascript:void(0)' onclick='audit("+b.id+",0)'>撤销审核</a>";
                    }
                    return str
                }
            }],
            buttons: [],
            pageLength: 10,
            dom: '<"toolbar">frtip'
        })
        // $("div.toolbar").html($('#toolbar').html());
        pageindex=0;
    }
    search(-1);
    $('#list tbody').on( 'click', 'tr', function () {
        window.history_list.$('tr.selected').removeClass('selected');
        $(this).addClass('selected');
        rowdata = window.history_list.row('.selected').data();
        rowdata.page=window.history_list.page();
    } );
    function preview(){
        loadPage('sys-page/website_manage/activity_preview.html','发布活动预览');
    }
    function audit(id,status){
        var pm = {"id":id,"status":status};
        swal({
                title: "活动审核",
                text: "请填写审批意见：",
                type: "input",
                showCancelButton: true,
                closeOnConfirm: false,
                closeOnCancel: true,
                animation: "slide-from-top",
                inputPlaceholder: "审批意见" ,
                confirmButtonText: "确定",
                cancelButtonText: "取消",
            },
            function(inputValue,isConfirm){
                if (inputValue === false) return false;
                pm["comment"]=inputValue;
                updateStatus(pm);
            });
    }
    function updateStatus(pm){
        $.getJSON({
            url: bathpath + "/activity/updateStatus",
            type: 'post',
            contentType: "application/json",
            data: JSON.stringify(pm)
        }).done(function(data) {
            if (ajaxdatacheck(data)) {
                if (data.code == 1) {
                    swal("操作提示", "操作成功","success");
                    window.history_list.draw(false);
                } else {
                    swal("操作提示", "操作失败","error");
                }
            }
        })
            .fail(function(e) {
                console.error(e)
            })
            .always(function() {
                console.log('done!')
            })
    }

</script>

